package com.camera.yl.v

import android.widget.Button
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.camera.base.v.BaseActivity
import com.camera.base.v.BaseFragment
import com.camera.routemodule.RouterPath
import com.camera.yl.R
import com.camera.yl.adapter.HomePagerAdapter
import com.camera.yl.bean.TabBean
import com.camera.yl.databinding.ActivityNetPlatformSettingsBinding
import com.camera.yl.v.models.NetPlatformSettingsViewModel
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
@Route(path = RouterPath.path.net_platform_settings_activity)
class NetPlatformSettingsActivity: BaseActivity<ActivityNetPlatformSettingsBinding,NetPlatformSettingsViewModel>() {
    private val TAG = "NetPlatformSettingsActivity";
    private val dataList: MutableList<TabBean> = ArrayList()
    override val viewModelClass: Class<NetPlatformSettingsViewModel>
        get() = NetPlatformSettingsViewModel::class.java
    override fun getLayoutId(): Int {
        return R.layout.activity_net_platform_settings
    }
    override fun getStatusBarColor(): Int{
        return R.color.title_background_color
    }
    override fun loadData() {
        dataList.clear()
        mBinding.viewModel = viewModel

        val fragmentGB: Fragment? = ARouter.getInstance().build(RouterPath.path.gbsetting_fragment).navigation() as? Fragment
        fragmentGB?.let {
            dataList.add(TabBean(getString(R.string.gb_setting), it))
        }
        val fragmentRtspServer: Fragment? = ARouter.getInstance().build(RouterPath.path.rtspserver_fragment).navigation() as? Fragment
        fragmentRtspServer?.let {
            dataList.add(TabBean(getString(R.string.rtsp_setting), it))
        }

        mBinding.viewpager.adapter = HomePagerAdapter(supportFragmentManager, dataList)
        mBinding.tablayout.setupWithViewPager(mBinding.viewpager, false)
        mBinding.viewpager.currentItem = 0
        mBinding.viewpager.offscreenPageLimit = dataList.size
        //设置TabItem的View(一定要在设置完适配器之后进行设置)
        mBinding.tablayout.addOnTabSelectedListener(object : com.google.android.material.tabs.TabLayout.OnTabSelectedListener {
            override fun onTabSelected(tab: com.google.android.material.tabs.TabLayout.Tab) {

            }

            override fun onTabUnselected(tab: com.google.android.material.tabs.TabLayout.Tab) {
            }

            override fun onTabReselected(tab: com.google.android.material.tabs.TabLayout.Tab) {
                //选中之后再次点击即复选时触发
            }
        })
    }

    override fun onBackPressed() {
        if((dataList.get(mBinding.viewpager.currentItem).fragment as BaseFragment<*>).onBack()) {
            super.onBackPressed()
        }
    }

    override fun initView() {

    }

    override fun onDestroy() {
        super.onDestroy()
    }
}